home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / strategy / tictac2-.000 / tictac2- / tictac2 / moves.c < prev    next >
C/C++ Source or Header  |  1980-01-04  |  4KB  |  89 lines

  1. /*****************************************************************************.
  2. **  TicTac2:  Simple TicTacToe two-player game against another user or cpu.  **
  3. **  Copyright (c) 1995 Ian Singh                                             **
  4. **                                                                           **
  5. **  This program is free software; you can redistribute it and/or modify it  **
  6. **  under the terms  of the  GNU General Public License as published by the  **
  7. **  Free Software Foundation;  either version 2 of the License, or (at your  **
  8. **  option) any version later.                                               **
  9. **                                                                           **
  10. **  This program is distriubted in the hope that it  will  be  useful,  but  **
  11. **  WITHOUT   ANY   WARRANTY;   without   even   the  implied  warranty  of  **
  12. **  MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PURPOSE.   See  the  GNU  **
  13. **  General Public License for more details.                                 **
  14. **                                                                           **
  15. **  You should have received a copy of the GNU General Public License along  **
  16. **  with  this  program;   if not,  write  to the Free Software Foundation,  **
  17. **  Inc.,  675 Mass Ave, Cambridge, MA 02139, USA.                           **
  18. **                                                                           **
  19. **  Ian Singh                           Ian Singh                            **
  20. **  am256@freenet.carleton.ca           3G Arnold Dr.                        **
  21. **                                      Nepean, Ontario                      **
  22. **                                      K2H 6V6                              **
  23. .*****************************************************************************/
  24.  
  25. /* +-----------------------------------------------------------------------+ **
  26. ** |  moves.c:  move routines for my game                                  | **
  27. ** |                                                                       | **
  28. ** +-----------------------------------------------------------------------+ */
  29.  
  30. #include <stdio.h>
  31. #include "tictac2.h"
  32. #include "moves.h"
  33. #include "screen.h"
  34. #include "ai.h"
  35. /*
  36. ** getmove(player):  get's a move from a player and put's it on field 
  37. **  actually this routines just calls getmove_xx; where xx is what status is.
  38. */
  39. void getmove(player p, char *field)
  40. {
  41.   switch(p.status)  {
  42.   case HUMAN_YOU:  getmove_human_you(p, field);  break;
  43.   case CPU:        getmove_cpu(p, field);  break;
  44.   }
  45.  
  46. /*
  47. ** get's a move from (me) using selectspace() or whatever.
  48. ** and put it in field[]
  49. */
  50.  
  51. void getmove_human_you(player p, char *field)
  52. {
  53.   int tmp;
  54.  
  55.   tmp=selectspace(field);
  56.   if ( tmp==I_QUIT ) abort();
  57.   else field[ (tmp-1) ] = p.num;
  58.  
  59.  
  60. int checkocc(int p1, int p2, int p3, char *s )
  61. {
  62.   if((s[p1]+s[p2]+s[p3])==3)  return 1;
  63.   else if((s[p1]+s[p2]+s[p3])==30)  return 10;
  64.   else return 0;
  65. }
  66.  
  67. int checkwin(char *field)
  68. {
  69.    int tmp;   
  70.  
  71.    if ( tmp=checkocc(0,1,2,field) ) return tmp;
  72.    else if ( tmp=checkocc(3,4,5,field) ) return tmp;
  73.    else if ( tmp=checkocc(6,7,8,field) ) return tmp;
  74.    else if ( tmp=checkocc(0,3,6,field) ) return tmp;
  75.    else if ( tmp=checkocc(1,4,7,field) ) return tmp;
  76.    else if ( tmp=checkocc(2,5,8,field) ) return tmp;
  77.    else if ( tmp=checkocc(0,4,8,field) ) return tmp;
  78.    else if ( tmp=checkocc(2,4,6,field) ) return tmp;
  79.    else if ( field[0]&&field[1]&&field[2]&&field[3]&&field[4]&&field[5]&&
  80.        field[6]&&field[7]&&field[8] ) return 3;
  81.    else return 0;
  82. }
  83.  
  84.  
  85.  
  86.  
  87.